<template>
	<view>
		<Header :isBack="true">
			<block slot="content">{{title}}</block>
		</Header>
		<view class="place"></view>

		<view class="input-box" style="">
			<textarea auto-height disable-default-padding auto-focus show-confirm-bar placeholder="说出你的想法" class="input"
				v-model="value" style="font-size: 28upx;"></textarea>
		</view>

		<view class="d-flex" style="width: 94%; flex-wrap: wrap; margin-left: 3%;">
			<view class="">
				<uploads :type="code"></uploads>
			</view>
		</view>

		<view class="" style="height: 20rpx;"></view>
		<view class="cover_img" style="">
			<view class="cover_img-text">封面图
				<!-- <text v-show="code == 2">（上传视频必须上传封面图）</text> -->
			</view>
			<view class="" style="width: 140upx;">
				<robby-image-upload :src="cover_img" :width="width" :height="height" :lineheight="lineheight"
					:borderRadius="borderRadius"></robby-image-upload>
			</view>
		</view>

		<view class="lssue" @tap="lssue">发布</view>
	</view>
</template>

<script>
	import uploads from "@/components/uploads.vue";
	import robbyImageUpload from '@/components/robby-image-upload/robby-image-upload.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				title: '作品发布',
				height: '140rpx',
				lineheight: '140rpx',
				width: '140rpx',
				borderRadius: '',
				value: '',
				VideosData: '',
				code: '1',
				videolist: [],
				cover_img: '/static/images/WechatI.png'
			}
		},
		components: {
			robbyImageUpload,
			uploads
		},
		computed: {
			...mapState(['hasLogin'])
		},

		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			let result = this.$api.isLogin();
			if (result === false) {
				return false;
			}
			this.code = option.type

			uni.setStorageSync('uploadType', 'cover')

			uni.$on('change', (options) => {
				this.VideosData = JSON.stringify(options)
			})

			uni.$on('changeCover', (option) => {
				let data = JSON.parse(option)
				this.cover_img = data.data
			})
		},
		methods: {
			...mapMutations(['login', 'logout']),

			async lssue() {
				let DataS = this.VideosData
				if (!DataS) {
					this.$api.msg('请上传资源')
					return false;
				}

				let type = this.code;

				let coverImg = (this.cover_img == '' || this.cover_img === '/static/images/WechatI.png') ? '' : this
					.cover_img;
				// if (type == 2 && coverImg == '') {
				// 	this.$api.msg('请上传封面图')
				// 	return false;
				// }

				let res = await this.$myRequest({
					url: '/add_video',
					methods: "POST",
					data: {
						cate: uni.getStorageSync('cate'),
						token: uni.getStorageSync('token'),
						type: type,
						content: this.value,
						data: DataS,
						cover_img: coverImg
					}
				})
				if (res.data.status == 1) {
					this.$api.msg('发布成功')
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages5/pages/video-resources/user-video'
						})
					}, 1500)
				}
			},
		}
	}
</script>
<style lang='scss'>
	.flex-1 {
		flex: 1;
	}

	.d-flex {
		display: flex;
	}

	.place {
		// #ifdef H5
		height: 100upx;
		// #endif
		// #ifdef MP-WEIXIN
		height: 160upx;
		// #endif

		// #ifdef APP-PLUS
		height: 160upx;
		// #endif
	}

	.position {
		background-color: #f7f7f7;
		width: 96%;
		margin: 0 auto;
		padding: 20rpx;
		border-radius: 20rpx;
	}

	.lssue {
		position: absolute;
		bottom: 76upx;
		height: 90upx;
		background-color: #e80808;
		color: white;
		padding: 5rpx;
		width: 94%;
		margin-left: 3%;
		text-align: center;
		border-radius: 45rpx;
		font-weight: normal;
		display: flex;
		align-items: center;
		justify-content: center;
		letter-spacing: 4upx;
	}

	.input-box {
		width: 94%;
		margin-left: 3%;
		padding: 62upx 0;
	}

	.input {
		width: 100%;
		/* padding: 10rpx; */

	}

	.input-image {
		width: 200rpx;
		margin-left: 10rpx;
		margin-top: 10rpx;
	}

	.cover_img {
		display: block;
		margin-left: 3%;
	}

	.cover_img-text {
		font-size: 28upx;
		line-height: 50upx;
		height: 50upx;
	}
</style>
